package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.CancelNursingTaskDto;
import com.zzyl.nursing.dto.DoNursingTaskDto;
import com.zzyl.nursing.dto.NursingTaskPageDto;
import com.zzyl.nursing.dto.UpdateEstimatedTimeDto;
import com.zzyl.nursing.vo.NursingTaskDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * nursingTaskController
 * 
 * @author ruoyi
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "nursingTask相关接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 查询nursingTask列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取nursingTask列表")
    public TableDataInfo<List<NursingTask>> list(NursingTaskPageDto dto)
    {
        startPage();

        List<NursingTask> list = nursingTaskService.selectNursingTaskList(dto);
        return getDataTable(list);
    }

    /**
     * 获取nursingTask详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取nursingTask详细信息")
    public R<NursingTaskDetailVo> getInfo(@ApiParam(value = "nursingTaskID", required = true)
            @PathVariable("id") Long id)
    {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }

    /**
     * 新增nursingTask
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:add')")
    @Log(title = "nursingTask", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增nursingTask")
    public AjaxResult add(@ApiParam(value = "nursingTask实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.insertNursingTask(nursingTask));
    }

//    /**
//     * 修改nursingTask
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:edit')")
//    @Log(title = "nursingTask", businessType = BusinessType.UPDATE)
//    @PutMapping
//    @ApiOperation("修改nursingTask")
//    public AjaxResult edit(@ApiParam(value = "nursingTask实体", required = true) @RequestBody UpdateEstimatedTimeDto dto)
//    {
//        return toAjax(nursingTaskService.updateNursingTask(dto));
//    }

    /**
     * 删除nursingTask
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:remove')")
    @Log(title = "nursingTask", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除nursingTask")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(nursingTaskService.deleteNursingTaskByIds(ids));
    }

    /**
     * 执行任务
     * @param doNursingTaskDto
     * @return
     */
    @PutMapping("/do")
    public AjaxResult doTask(@RequestBody DoNursingTaskDto  doNursingTaskDto){
        nursingTaskService.doTask(doNursingTaskDto);
        return success();
    }

    /**
     * 取消任务
     * @param dto
     * @return
     */
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody CancelNursingTaskDto dto){
        boolean flag = nursingTaskService.cancel(dto);
        if(flag){
            return success();
        }
        return error();
    }

    /**
     * 任务改期
     * @param dto
     * @return
     */
    @PutMapping("/updateTime")
    public AjaxResult updateTime(@RequestBody UpdateEstimatedTimeDto dto){
    boolean flag = nursingTaskService.updateTime(dto);
    if(flag){
        return success();
    }
    return error();
    }
}
